package ext.tianma.doc.util;

import java.util.List;
import java.util.Locale;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import ext.tianma.number.util.DocUtil;
import wt.doc.WTDocument;
import wt.util.WTException;

public class DCCInquireStatementService {
	private static Locale LOCALE = Locale.CHINA;
	
	public static String getStatementByDocTypeAndRepository(String docType, String repository, String docName, String startdate, String enddate, String modulesDevelopedLand, String moduleOrigin, String controlDocumentNum, String states) throws WTException, JSONException {

		JSONObject ob = new JSONObject();
		JSONArray array = new JSONArray();
		boolean isExit = false;
		String drawingType = "";
		try {
			List<WTDocument> list = DCCInquireStatementHelp.getDocByTypeAndRepository(docType ,repository, docName, startdate, enddate, modulesDevelopedLand, moduleOrigin, controlDocumentNum, states);
			WTDocument doc = null;
			for(int i =0; i<list.size(); i++) {
				doc = list.get(i);
				String docNumber = doc.getNumber(); // 获得文档编号
				doc = DocUtil.getWTDocumentByNumber(docNumber);//根据文档编号获取最新文档对象
				String name = doc.getName();
				drawingType = wt.type.ClientTypedUtility.getLocalizedTypeName(doc, LOCALE);//获得文档类型显示名称
					isExit = true;
					if(-1!=name.indexOf("临时图纸")) {
						String type = "是"; //是否临时图纸
						DCCInquireStatementHelp.saveStatement(ob, array, doc, type, drawingType, name);
						
					}else {
						String type = "否";//是否临时图纸
						DCCInquireStatementHelp.saveStatement(ob, array, doc, type, drawingType, name);
					}
			}
		} catch (Exception e) {
			ob.put("status", "error");
			ob.put("message", "接口错误！");
			e.printStackTrace();
		}
		if(!isExit) {
			ob.put("status", "false");
			ob.put("message", "未查到！");
		}
		return ob.toString();
	}
	
}
